package cn.zcy.springboot_web.aspect;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;



@Aspect
@Component
public class LogAspect {
    Logger logger = LoggerFactory.getLogger(LogAspect.class);

    @Around("execution(* cn.zcy.springboot_web.controller.*.*(..)) &&" +
            "@annotation(apiOperation)")
    public Object around(ProceedingJoinPoint point, ApiOperation apiOperation) throws Throwable {
        StringBuilder logInfo = new StringBuilder("用户访问了：");
         //获取类
        Class<?> controller = point.getThis().getClass();
        //获取类上的注解
        Api api = controller.getAnnotation(Api.class);
        if (api!= null) {
            logger.info("api.value()=="+api.value());
            logInfo.append(api.value());
        }
        String value = apiOperation.value();

        logInfo.append("-----"+value);
        logger.info(logInfo.toString());
        return point.proceed();
    }
}
